package com.cyf.filmDownload.m3u8.entity;

import lombok.Getter;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 下载进度
 */
@Getter
public class DownloadProgress {

    private M3u8ParserResult parserResult;

    private int total;
    private AtomicInteger finish;

    private long startTime;

    public DownloadProgress(M3u8ParserResult parserResult) {
        this.parserResult = parserResult;
        this.total = parserResult.getTsList().size();
        this.finish = new AtomicInteger(0);
        this.startTime = System.currentTimeMillis();
    }

    public void increaseFinish() {
        finish.incrementAndGet();
    }

    public boolean isFinish() {
        return finish.get() >= total;
    }

    public String getProgress() {
        long consumeSecond = (System.currentTimeMillis() - startTime) / 1000;
        return "已用时：" + consumeSecond + "秒, 完成：" + finish + "个，还剩：" + (total - finish.get()) + "个";
    }
}